package direcLength;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class t1 {
    public static void main(String[] args) {
        File f = new File("/Users/tkf/Desktop/7.java基础/javaBase/homeExtendDay12/src/main/java/direcLength/demo");
        System.out.println(getLens(f));
    }
    static Map<String,Integer> res = new HashMap<>();

    public  static Map<String, Integer> getLens(File f){
        File[] files = f.listFiles();
        if (files != null) {
            for (File file : files) {
                if(file.isFile()){
                    if(file.getName().endsWith("txt")){
                        Integer txt = res.get("txt");
                        if(txt == null) txt = 0;
                        res.put("txt",txt+1);
                    }else if(file.getName().endsWith("png")){
                        Integer png = res.get("png");
                        if(png == null) png = 0;

                        res.put("png",png+1);
                    }
                }else{
                    if(file.listFiles() !=null){
                        getLens(file);
                    }
                }
            }
        }
        return res;
    }

}
